package com.lagou.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientInitClose {

    private Socket socket;
    private ObjectOutputStream oos;
    private ObjectInputStream ois;

    public ObjectOutputStream getOos() {
        return oos;
    }

    public void setOos(ObjectOutputStream oos) {
        this.oos = oos;
    }

    public ObjectInputStream getOis() {
        return ois;
    }

    public void setOis(ObjectInputStream ois) {
        this.ois = ois;
    }

    /**
     * 自定义成员方法实现客户端的初始化
     *
     * @throws IOException
     */
    public void clientInit() throws IOException {

        //创建Socket
        socket = new Socket(InetAddress.getLocalHost(), 8888);

        //使用输入输出流通信
        oos = new ObjectOutputStream(socket.getOutputStream());
        ois = new ObjectInputStream(socket.getInputStream());
        System.out.println("连接服务器成功！");

    }


    /**
     * 自定义成员方法实现客户端关闭
     *
     * @throws IOException
     */
    public void clientClose() throws IOException {

        ois.close();;
        oos.close();
        socket.close();
        System.out.println("客户端关闭成功！");
    }


}
